package study.javaee.practice.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import study.javaee.practice.common.annotation.CreateValidate;
import study.javaee.practice.common.annotation.UpdateValidate;

import javax.validation.constraints.*;
import java.io.Serializable;

@Data
public class User implements Serializable {
    @ApiModelProperty(value = "用户id")
    @TableId(type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "姓名")
    @NotEmpty(message = "姓名不能为空",groups = {CreateValidate.class, UpdateValidate.class})
    @Length(max = 10, message = "姓名长度不超过10",groups = {CreateValidate.class, UpdateValidate.class})
    private String name;

    @ApiModelProperty(value = "用户email,登录时使用")
    @NotEmpty(groups = {CreateValidate.class, UpdateValidate.class})
    @Email(groups = {CreateValidate.class, UpdateValidate.class})
    private String email;

    @ApiModelProperty(value = "密码")
    @NotEmpty(message = "密码不能为空")
    @Length(min = 6, max = 20, message = "密码长度在6到20之间", groups = {CreateValidate.class})
    @Pattern(regexp = "(?:.{6,20})|(?:)", groups = {UpdateValidate.class})
    private String password;

    @ApiModelProperty(value = "性别")
    @NotEmpty(groups = {CreateValidate.class, UpdateValidate.class})
    @Pattern(regexp = "[男女]", message = "性别值错误", groups = {UpdateValidate.class, CreateValidate.class})
    private String sex;

    @ApiModelProperty(value = "1为科研人员；2为领导；3为系统管理员")
    @NotNull(groups = {UpdateValidate.class})
    @Range(min = 1,max = 3, groups = {CreateValidate.class, UpdateValidate.class})
    private Integer type;

    private static final long serialVersionUID = 1L;

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", name=").append(name);
        sb.append(", email=").append(email);
        sb.append(", password=").append(password);
        sb.append(", sex=").append(sex);
        sb.append(", type=").append(type);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}